package reflect

import (
	"beergo/lib/tool"
	"reflect"
	"strings"
)

func ValueOf(model interface{}, fields string) reflect.Value {
	strSlice := strings.Split(fields, ".")
	var value reflect.Value
	value = reflect.ValueOf(model)
	for index, field := range strSlice {
		if index == 0 {
			value = value.FieldByName(tool.Ucfirst(field))
		} else {
			value = value.Elem().FieldByName(tool.Ucfirst(field))
		}
	}
	return value
}
